<?php

namespace App\Http\Controllers\Plugin;


use App\Helpers\ResponseData;
use Illuminate\Http\Request;
class UploadImageController
{

    use OssController,ResponseData;
    //input 上传
    public function file_upload($request){
        if ($request->hasFile('thumb_url') && $request->file('thumb_url')->isValid()) {
            info('存在说略图');
            $path = $this->commonUpload($request->file('thumb_url'));
            return $path;
        }else{
            info('不存在缩略图');
            return '';
        }
        return '';
    }
    //video 上传
    public function video_upload($request){
        if ($request->hasFile('video') && $request->file('video')->isValid()) {
            $path = $this->commonUpload($request->file('video'));
            return $path;
        }
        return '';
    }
    //单图上传
    public function upload(Request $request){
        if ($request->hasFile('file') && $request->file('file')->isValid()) {
            $path = $this->commonUpload($request->file('file'));
            return $this->success($path);
        }else{
            return $this->failed($request->all(),201);
        }
    }
    //多图上传
    public function multiImgs(Request $request){
        if ($request->hasFile('file') && $request->file('file')->isValid()) {
            foreach($request->hasFile('file') as $item){
                $path[] = $this->commonUpload($item);
            }
            return $this->success($path);
        }else{
            return $this->failed($request->all(),201);
        }
    }
}
